import java.util.*;

public class KingSort {

	static String[] ones = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"};
	static String[] tens = {"", "X", "XX", "XXX", "XL", "L"};
	static Map<String, Integer> map = new HashMap<String, Integer>();
	
	static {
		for (int i=1; i<=50; i++) {
			map.put(tens[i/10]+ones[i%10], i);
		}
	}
	
			
	
	public String[] getSortedList(String[] kings) {
		Arrays.sort(kings, new Comparator<String>() {

			public int compare(String k1, String k2) {
				String[] kk1 = k1.split(" ");
				String[] kk2 = k2.split(" ");
				if (kk1[0].equals(kk2[0])) {
					return map.get(kk1[1]).compareTo(map.get(kk2[1]));
				} else return kk1[0].compareTo(kk2[0]); 
			}
		});
		return kings;
	}

}
